package com.bank.basic.service.impl;

import com.bank.basic.service.StandardService;
import com.bank.basic.util.EntityFactory;
import com.bank.basic.util.MapperFactory;
import com.bank.model.entity.Standard;
import com.bank.model.vo.standard.StandardVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author callumEm
 * @version 1.0
 * @create 2023/4/19 15:25
 */
@Service
public class StandardServiceImpl implements StandardService {
    @Autowired
    EntityFactory entityFactory;
    @Autowired
    MapperFactory mapperFactory;

    @Override
    public List<Standard> queryStandardService() {
        List<Standard> standardServices = mapperFactory.getStandardMapper().selectList(null);
        return standardServices;
    }

    @Override
    public void updateStandardService(String name, String content) {
        QueryWrapper<Standard> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("name",name);
        Standard standard = mapperFactory.getStandardMapper().selectOne(queryWrapper);
        standard.setContent(content);
        mapperFactory.getStandardMapper().updateById(standard);
    }

    @Override
    public void updateStandardService(Standard standard) {
        updateStandardService(standard.getName(),standard.getContent());
    }

    @Override
    public void addStandardService(String name, String content) {
        Standard standard = entityFactory.getStandard(name,content);
        mapperFactory.getStandardMapper().insert(standard);
    }

    @Override
    public void addStandardService(StandardVo standardVo) {
        Standard standard = entityFactory.getStandard(standardVo);
        mapperFactory.getStandardMapper().insert(standard);
    }
}
